package eu.dominicum.ft.pd.mao.validator;

import eu.dominicum.ft.pd.mao.MakeStageResultMAO;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Custom validator to validate between the properties location and locationID.
 *
 * @author Harry Klerks
 * @since 2013M1
 */
public class NewOrExistingLocationValidator
        implements ConstraintValidator<NewOrExistingLocation,
        MakeStageResultMAO> {

    @Override
    public void initialize(final NewOrExistingLocation newOrExistingLocation) {

    }

    @Override
    public final boolean isValid(final MakeStageResultMAO makeStageResultMAO,
                                 final ConstraintValidatorContext constraintValidatorContext) {

        Long locationId = makeStageResultMAO.getLocationId();
        String locationName = makeStageResultMAO.getMakeLocationMAO().getName();

        return locationName != null || locationId != null;
    }

}
